package com.heima.feign.falback;

import com.heima.model.article.pojos.ApAuthor;
import com.heima.feign.ArticleFeignClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ArticelFeignFallback  implements FallbackFactory<ArticleFeignClient> {
    @Override
    public ArticleFeignClient create(Throwable throwable) {
        return new ArticleFeignClient() {
            @Override
            public ResponseResult<ApAuthor> findByUserId(Integer userId) {
                log.info("参数:{}",userId);
                log.error("ArticleFeignClient 的调用，findByUserId方法，出错了{}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult save(ApAuthor apAuthor) {
                log.info("参数:{}",apAuthor);
                log.error("ArticleFeignClient 的调用，save方法，出错了{}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }
        };
    }
}
